#include "sym.h"

SYMS SYM;
std::string nameSym(SYMS sym)
{
  switch (sym)
  {
  case SYMS::CONST:
    return "CONSTSYM";
    /* code */
    // 关键字
  case SYMS::VAR:
    return "VARSYM";
  case SYMS::BEGIN:
    return "BEGINSYM";
  case SYMS::END:
    return "ENDSYM";
  case SYMS::IF:
    return "IFSYM";
  case SYMS::THEN:
    return "THENSYM";
  case SYMS::WHILE:
    return "WHILESYM";
  case SYMS::DO:
    return "DOSYM";
  case SYMS::READ:
    return "READSYM";
  case SYMS::WRITE:
    return "WRITESYM";
  case SYMS::ELSE:
    return "ELSESYM";
  case SYMS::PROCEDURE:
    return "PROCSYM";
  case SYMS::ODD:
    return "ODDSYM";
  case SYMS::REPEAT:
    return "REPEATSYM";
  case SYMS::UNTIL:
    return "UNTILSYM";
  case SYMS::CALL:
    return "CALLSYM";
  case SYMS::COMMA:
    return "COMMA";
  case SYMS::SEMICOLON:
    return "SEMICOLON";
  case SYMS::DOT:
    return "PERIED";
  case SYMS::LEFT_BRACKET:
    return "LPAREN";
  case SYMS::RIGHT_BRACKET:
    return "RPAREN";
  case SYMS::COLON:
    return "COLON";
  case SYMS::LESS:
    return "LESS";
  case SYMS::GREATER:
    return "GREATER";
  case SYMS::PLUS:
    return "PLUS";
  case SYMS::MINUS:
    return "MINUS";
  case SYMS::LESS_EQUAL:
    return "LESS_EQUAL";
  case SYMS::RIGHT_EQUAL:
    return "GREATER_EQUAL";
  case SYMS::NOT_EQUAL:
    return "NOT_EQUAL";
  case SYMS::EQUAL:
    return "EQUAL";
  case SYMS::VAR_ASSIGN:
    return "ASSIGN";
  case SYMS::MULTIPLY:
      return "TIMES";
  case SYMS::DIVIDE:
      return "SLASH";
  case SYMS::NUMBER:
    return "NUMBER";
  case SYMS::IDENT:
    return "IDENT";
  case SYMS::NILL:
    return "NILL";
  default:
    break;
  }
}
TOKEN::TOKEN() {
    sym=SYMS::NILL;
    id = "";
    num = 0;
};
TOKEN::TOKEN(SYMS _sym,const std::string& _id,int _num, const std::string& _word) {
    sym = _sym;
    id = _id;
    num = _num;
    word = _word;
}
TOKEN* TOKEN::newKey(SYMS _sym,const std::string& word) {
    return new TOKEN(_sym,"",0,word);
}
TOKEN* TOKEN::newID(const std::string& _id,const std::string& word) {
    return new TOKEN(SYMS::IDENT,_id,0,word);
}
TOKEN* TOKEN::newNum(int _num,const std::string& word) {
    return new TOKEN(SYMS::NUMBER,"",_num,word);
}
TOKEN* TOKEN::newOpt(SYMS _sym,const std::string& word) {
    return new TOKEN(_sym,"",0,word);
}

std::ostream& operator<<(std::ostream& os,const TOKEN& obj) {
    os <<std::left<<"WORD:"<<std::setw(15)<<obj.word<< "SYM:" << std::setw(15) << nameSym(obj.sym) << '\t' << "ID:" << std::setw(10) << obj.id << '\t' << "NUM:" << std::setw(10) << obj.num << std::endl;
}
